<?php


namespace app\api\logic;

use app\common\logic\BaseLogic;
use app\common\model\user\User;
use app\common\service\ConfigService;
use app\common\service\FileService;
use think\facade\Config;

/**
 * 注册逻辑层
 * Class RegisterLogic
 * @package app\api\logic
 */
class RegisterLogic extends BaseLogic
{
    public static function register($params)
    {
        try {
            $defaultAvatar = ConfigService::get('config', 'default_avatar',  FileService::getFileUrl(config('project.default_image.user_avatar')));
            $passwordSalt = Config::get('project.unique_identification');
            $password = create_password($params['password'], $passwordSalt);
            // 创建用户
            $data = [
                'channel' => $params['channel'],
                'sn' => create_user_sn(),
                'nickname' => $params['mobile'],
                'avatar' => $defaultAvatar,
                'mobile' => $params['mobile'],
                'account' => $params['mobile'],
                'password' => $password,
            ];
            $user = User::create($data);

            return true;
        } catch(\Exception $e) {
            self::setError($e->getMessage());
            return false;
        }
    }




}